﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using CefSharp;
using CefSharp.WinForms;

namespace browserplayform
{
    public partial class cefsharpform : Form
    {
        ChromiumWebBrowser browser = new ChromiumWebBrowser("");

        public cefsharpform()
        {
            InitializeComponent();
            

        }

        public void InitBrowser()
        {
            try
            {
                BrowserSettings bset = new BrowserSettings();
                bset.Plugins = CefState.Enabled;
                //关于跨域限制
                bset.WebSecurity = CefState.Disabled;
                browser.BrowserSettings = bset;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            

        }

        private void button_go_Click(object sender, EventArgs e)
        {
            try {
                string url_tmp = this.richTextBox_url.Text;
                if (url_tmp != "")
                {
                    browser.Load(url_tmp);
                    this.Controls.Add(browser);
                    browser.Dock = DockStyle.Fill;
                    browser.Update();
                    
                    
                }
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }





        private void cefsharpform_Load(object sender, EventArgs e)
        {
            try
            {
                InitBrowser();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}
